(function(){

    fetch('http://chst.vip:1234/api/getbaicaijiatitle')
    .then(body=>body.json())
    .then(res=>{
        // console.log(res);



        // let result= res.result[0]
        // ${result.}
        let html=""

        res.result.forEach(item => {

            html+=
            `
            <li titleId=${item.titleId}>${item.title}</li>
        
            `
        });
        $('#nav div ul').html(html)



        fetch(`http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0`)
    .then(body=>body.json())
    .then(res=>{
        console.log(res);

        // ${result.}
        let html=""

        res.result.forEach(item => {

            html+=
            `
            <li productId=${item.productId}>
            <div class="img">${item.productImg}
            </div>
            <div class="infoR">
                <div class="title">
                    <h4>${item.productName}</h4>
                    <div class="price">
                        ${item.productPrice}
                    </div>
                </div>
                <div class="down">
                    <div class="bar">
                        <div class="bar_in">0%</div>
                    </div>
                    <span class="yiling">已领0张/剩余126张</span>
                    <div class="click">
                        <div class="left">点此领取优惠券</div>
                        <div class="right">下单链接</div>
                    </div>
                </div>
            </div>
        </li>
            `
        });

        $('#section ul').html(html)
    })
        

        let lis= [...$('#nav div ul li')]

        // console.log(lis);

        lis.forEach(li=>{
            // console.log(li);

            li.onclick=function(){
                let titleId= this.getAttribute('titleid')
                console.log(titleId);

    fetch(`http://chst.vip:1234/api/getbaicaijiaproduct?titleid=${titleId}`)
    .then(body=>body.json())
    .then(res=>{
        // console.log(res);

        // ${result.}
        let html=""

        res.result.forEach(item => {

            html+=
            `
            <li productId=${item.productId}>
            <div class="img">${item.productImg}
            </div>
            <div class="infoR">
                <div class="title">
                    <h4>${item.productName}</h4>
                    <div class="price">
                        ${item.productPrice}
                    </div>
                </div>
                <div class="down">
                    <div class="bar">
                        <div class="bar_in">0%</div>
                    </div>
                    <span class="yiling">已领0张/剩余126张</span>
                    <div class="click">
                        <div class="left">点此领取优惠券</div>
                        <div class="right">下单链接</div>
                    </div>
                </div>
            </div>
        </li>
            `
        });

        $('#section ul').html(html)
    })
                
    }
})

   
})


})()